package com.example.admin.sjb;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by admin on 2017/11/7.
 */

public class PeopleActivity extends AppCompatActivity {
    private TextView tv1;
    private TextView tv2;
    private ImageView iv;

    private int random = 0;
    private int play = 1,play1,play2;//用户出拳
    private Button bt1;
    private Button bt2;
    private Button bt3;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_people);

        tv1=(TextView)findViewById(R.id.textView);
        tv2=(TextView)findViewById(R.id.button4);
        iv=(ImageView)findViewById(R.id.imageView);
        bt2=(Button)findViewById(R.id.button);
        bt1=(Button)findViewById(R.id.button2);
        bt3=(Button)findViewById(R.id.button3);

        bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv.setImageResource(R.drawable.shi);
                play = 1;
            }
        });
        bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv.setImageResource(R.drawable.jian);
                play = 2;
            }
        });
        bt3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                iv.setImageResource(R.drawable.bu);
                play = 3;
            }
        });

    }
    public void RStart(View view){
        if(random == 0){
            random = 1;
            play1 = play;
            tv2.setText("请玩家2确认");
        }else if(random == 1){
            random = 2;
            play2 = play;
            if(play2 == play1){
                tv1.setText("平局");
            } else if((play1==3&&play2==1)||(play1==1&&play2==2)||(play1==2&&play2==3)){
                tv1.setText("玩家1赢");
            }else{
                tv1.setText("玩家2赢");
            }
            tv2.setText("重新开始");
        }else{
            random = 0;
            tv2.setText("请玩家1确认");
        }
    }
}
